<template>
  <div class="main" v-loading="reLoading">
     <van-pull-refresh v-model="isLoading" @refresh="onRefresh" >
       <van-list
        class="list-item"
        v-model="loading"
        :finished="finished"
        :finished-text="list.length === 0 ? '暂无数据' : '没有更多了'"
        @load="onLoad">
      <order-list-item v-for="(item, index) in list" :key="index" :obj="item" @call-father="onLoad"></order-list-item>
     </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import orderListItem from "./orderListItem";
import {getOrderList} from "../../../../api/shopping";

export default {
  name: "shopList",
  components: {orderListItem},
  props: {
    obj: {
      type: Object,
      required: true // 必传
    }
  },
  data() {
    return {
      activeParam: 0,
      list: [], // 数据列表
      loading: false, // 控制加载中的 loading 状态
      finished: false, // 控制加载结束的状态，当加载结束，不再触发加载更多
      current: 1, // 获取下一页数据current
      size: 10,
      isLoading:false,
      reLoading:false
    }
  },
  methods: {
    selectParam(item, index) {
      console.log(item)
      this.activeParam = index
      // this.choose.stapleFoodName = item.name
      // this.choose.stapleFoodType = item.value
    },
    async onLoad() {
      console.log('请求load接口', this.obj)
      const {data} = await getOrderList({
        status: this.obj.id,
        size: this.size,
        current: this.current,
      })
      if (data !== null) {
        const {records} = data
        this.list.push(...records)
        // this.list = records
        console.log('list', this.list)
        sessionStorage.setItem('homeData', JSON.stringify(this.list))
        // 3. 加载结束
        this.loading = false
          this.isLoading = false
         if (this.reLoading) {
          this.$toast('刷新成功')
          this.reLoading = false
         }
        if (records.length >= 10) {
          this.current += 1
        } else {
          this.finished = true
        }
        // if (records.length <= 0) {
        //   this.finished = true
        // } else {
        //   this.finished = false
        // }
      } else {
        this.finished = true
      }
    },
    onRefresh(){
      this.current = 1
      this.list = []
      this.reLoading = true
      this.onLoad()
    }
  }
}
</script>

<style scoped lang="less">
.main {
  .list-item {
    background: rgba(242, 242, 242, 1);
  }

  .content-top {
    padding: 12px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    background: rgba(255, 255, 255, 1);
    max-height: 154px;
    overflow-y: scroll;
    background: #F2EFEA;

    .selected {
      background-color: rgba(242, 150, 0, 1);
      border-color: rgba(242, 150, 0, 1) !important;
      color: #ffffff !important;
    }

    .content-item {
      //flex-shrink: 0;
      width: calc((100% - 18px) / 3);
      height: 27px;
      margin-right: 6px;
      opacity: 1;
      border-radius: 13.5px;
      border: 1px solid rgba(166, 166, 166, 1);
      margin-bottom: 10px;
      text-overflow: ellipsis;
      overflow: hidden;
      display: inline-block;
      white-space: nowrap;

      font-size: 14.55px;
      font-weight: 400;
      line-height: 25px;
      color: rgba(128, 128, 128, 1);
      text-align: center;
      vertical-align: top;
    }

    .content-item:nth-of-type(3n + 0) {
      margin-right: 0px;
    }
  }


}
</style>
